package com.example.demo.controller;

import com.example.demo.entity.XuanKe;
import com.example.demo.service.XuanKeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@Controller
@RequestMapping("/course")
public class CoursesController {

    @Autowired
    private XuanKeService xuanKeService;

    @PostMapping("/xuanke")
    @ResponseBody
    public Map<String,Object> xuanKe(@RequestBody XuanKe xuanKe){
        Map<String,Object> retData = new HashMap<>();
        if(xuanKe.getUsersId()== 0 || xuanKe.getCoursesId() == 0 || StringUtils.isEmpty(xuanKe.getTerms())){
            retData.put("code",500);
            retData.put("message","参数错误！");

        }else {
            retData =  xuanKeService.xuanKe(xuanKe.getUsersId(),xuanKe.getCoursesId(),xuanKe.getTerms());
        }
        log.debug("retData ====> {} ",retData);
        return retData;
    }


}